package com.example.config;

import com.example.foobar.business.service.DaRetentionRatesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

@Configuration
@EnableScheduling
public class ScheduleTaskConfig {
    @Autowired
    private DaRetentionRatesService daRetentionRatesService;

        // 秒 分 时 日 月 周 年
    @Scheduled(cron = "00 40 01 * * ?")
    public void pullActiveDate() {
        Date date = getYesterdayDate();

        daRetentionRatesService.pullActiveDateYingma(date);
//        daRetentionRatesService.pullActiveDate(date);
    }


    private Date getYesterdayDate() {
        return Date.from(LocalDate.now().plusDays(-1).atStartOfDay(ZoneId.systemDefault()).toInstant());
    }
}
